home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / WWW / Perl_WWW_Utilities / perlMIF_beta2 / mif / mif_varf.pl < prev    next >
Encoding:
Perl Script  |  1994-06-23  |  6.0 KB  |  183 lines

  1. ##---------------------------------------------------------------------------##
  2. ##  File:
  3. ##      mif_varf.pl
  4. ##  Author:
  5. ##      Earl Hood       ehood@convex.com
  6. ##  Description:
  7. ##    This file is defines the "mif_varf" perl package.  It defines
  8. ##    routines to handle the VariableFormats via MIFread_mif() defined in
  9. ##    the "mif" package.
  10. ##---------------------------------------------------------------------------##
  11. ##  Copyright (C) 1994  Earl Hood, ehood@convex.com
  12. ##
  13. ##  This program is free software; you can redistribute it and/or modify
  14. ##  it under the terms of the GNU General Public License as published by
  15. ##  the Free Software Foundation; either version 2 of the License, or
  16. ##  (at your option) any later version.
  17. ## 
  18. ##  This program is distributed in the hope that it will be useful,
  19. ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. ##  GNU General Public License for more details.
  22. ##  
  23. ##  You should have received a copy of the GNU General Public License
  24. ##  along with this program; if not, write to the Free Software
  25. ##  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. ##---------------------------------------------------------------------------##
  27.  
  28. require 'mif/mif.pl' || die "Unable to require mif.pl\n";
  29.  
  30. package mif_varf;
  31.  
  32. ##-------------------------------------------------##
  33. ## Add VariableFormats function to %MIFToken array ##
  34. ##-------------------------------------------------##
  35. $mif'MIFToken{'VariableFormats'} = 'VariableFormats';
  36.  
  37. ##------------------------------------##
  38. ## VariableFormats associative arrays ##
  39. ##------------------------------------##
  40. %VariableDef    = ();    # Variable definition
  41.  
  42. ##-------------------------------------------------##
  43. ## Variables for current VariableFormat definition ##
  44. ##-------------------------------------------------##
  45. $var_Name    = "";
  46. $var_Def    = "";
  47.  
  48. ##------------------------##
  49. ## Import 'mif' variables ##
  50. ##------------------------##
  51. $MStore        = $mif'MStore;
  52. $MOpen        = $mif'MOpen;
  53. $MClose        = $mif'MClose;
  54. $MLine        = $mif'MLine;
  55. $mso        = $mif'mso;
  56. $msc        = $mif'msc;
  57. $stb        = $mif'stb;
  58. $ste        = $mif'ste;
  59. $como        = $mif'como;
  60.  
  61.                 ##---------------##
  62.                 ## Main Routines ##
  63.                 ##---------------##
  64. ##---------------------------------------------------------------------------
  65. ##    MIFwrite_varf() outputs the VariableFormats as defined by the
  66. ##    associative arrays.
  67. ##
  68. ##    Usage:
  69. ##        &'MIFwrite_varf(FILEHANDLE);
  70. ##
  71. sub main'MIFwrite_varf {
  72.     local($handle, $l) = @_;
  73.     local($i0, $i1, $i2) = (' ' x $l, ' ' x (1+$l), ' ' x (2+$l));
  74.  
  75.     print $handle $i0, $mso, 'VariableFormats', "\n";
  76.     foreach (sort keys %VariableDef) {
  77.     print $handle $i1, $mso, "VariableFormat\n";
  78.     print $handle $i2, $mso, 'VariableName ', $stb, $_, $ste, $msc, "\n";
  79.     print $handle $i2, $mso, 'VariableDef ', $stb, $VariableDef{$_},
  80.                $ste, $msc, "\n";
  81.     print $handle $i1, $msc, " $como end of VariableFormat\n";
  82.     }
  83.     print $handle $i0, $msc, " $como end of VariableFormats\n";
  84. }
  85. ##---------------------------------------------------------------------------##
  86. ##    MIFget_variable_data() returns the data associated with the Frame
  87. ##    variable $variable.
  88. ##
  89. ##    Usage:
  90. ##        ($def) = &'MIFget_variable_data($variable);
  91. ##
  92. sub main'MIFget_variable_data {
  93.     local($variable) = @_;
  94.     ($VariableDef{$variable});
  95. }
  96. ##---------------------------------------------------------------------------##
  97. ##    MIFget_variables() returns a sorted array of all variables defined
  98. ##    in variable formats.
  99. ##
  100. ##    Usage:
  101. ##        @variables = &'MIFget_variables();
  102. ##
  103. sub main'MIFget_variables {
  104.     return sort keys %VariableDef;
  105. }
  106. ##---------------------------------------------------------------------------##
  107. ##    MIFreset_varf() resets the associative arrays for the variable
  108. ##    formats.
  109. ##
  110. ##    Usage:
  111. ##        &'MIFreset_varf();
  112. ##
  113. sub main'MIFreset_varf {
  114.     undef %VariableDef;
  115. }
  116. ##---------------------------------------------------------------------------##
  117.                 ##--------------##
  118.                 ## Mif Routines ##
  119.                 ##--------------##
  120. ##---------------------------------------------------------------------------##
  121. ##    The routines definded below are all registered in the %MIFToken         ##
  122. ##    array for use in the read_mif() routine.  There purpose is to         ##
  123. ##    store the information contained in VariableFormats.             ##
  124. ##---------------------------------------------------------------------------##
  125.  
  126. ##---------------------------------------------------------------------------
  127. ##    VariableFormats() is the token routine for 'VariableFormats'.
  128. ##    It sets/restores token routines depending upon mode.
  129. ##
  130. sub mif'VariableFormats {
  131.     local($token, $mode, *data) = @_;
  132.     if ($mode == $MOpen) {
  133.     ($_fast, $_noidata) = ($mif'fast, $mif'no_import_data);
  134.     ($mif'fast, $mif'no_import_data) = (1, 1);
  135.     @_v_orgfunc = @mif'MIFToken{
  136.                 'VariableFormat',
  137.                 'VariableName',
  138.                 'VariableDef'
  139.             };
  140.     @mif'MIFToken{
  141.         'VariableFormat',
  142.         'VariableName',
  143.         'VariableDef'
  144.     } = (
  145.         "mif_varf'VariableFormat",
  146.         "mif_varf'VariableName",
  147.         "mif_varf'VariableDef"
  148.     );
  149.     } elsif ($mode == $MClose) {
  150.     @mif'MIFToken{
  151.         'VariableFormat',
  152.         'VariableName',
  153.         'VariableDef'
  154.     } = @_v_orgfunc;
  155.         ($mif'fast, $mif'no_import_data) = ($_fast, $_noidata);
  156.     }
  157. }
  158. ##---------------------------------------------------------------------------
  159. sub VariableFormat {
  160.     local($token, $mode, *data) = @_;
  161.  
  162.     if ($mode == $MOpen) {
  163.     $var_Name = "";
  164.     $var_Def = "";
  165.     } elsif ($mode == $MClose) {
  166.     $VariableDef{$var_Name} = $var_Def;
  167.     } else {
  168.     warn "Unexpected mode, $mode, passed to VariableFormat routine\n";
  169.     }
  170. }
  171. ##---------------------------------------------------------------------------
  172. sub VariableName {
  173.     local($token, $mode, *data) = @_;
  174.     ($var_Name) = $data =~ /^\s*$stb([^$ste]*)$ste.*$/o;
  175. }
  176. ##---------------------------------------------------------------------------
  177. sub VariableDef {
  178.     local($token, $mode, *data) = @_;
  179.     ($var_Def) = $data =~ /^\s*$stb([^$ste]*)$ste.*$/o;
  180. }
  181. ##---------------------------------------------------------------------------
  182. 1;
  183.